﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MrPP.Myth;
using GDGeek;
using Mirror;

namespace MrPP.SerriedCabinet
{
    public class SetAsgardPose : NetworkBehaviour
    {
        [SyncVar(hook = "dataChange")]
        public Yggdrasil.AsgardPose _pose;

        [SerializeField]
        private bool _setPosition = true;
        [SerializeField]
        private bool _setRotation = true;
        [SerializeField]
        private bool _setScale = true;
/*
        public override void OnStartClient() {
            _pose =  Yggdrasil.Instance.getAsgardPose(new Yggdrasil.WorldPose(this.transform));
        }*/
        void refresh() {

            Yggdrasil.WorldPose world = Yggdrasil.Instance.getWorldPose(_pose);
            if (_setPosition)
            {
                transform.position = world.position;
            }
            if (_setRotation)
            {
                transform.rotation = Quaternion.LookRotation(world.forward, world.up);
            }
            if (_setScale)
            {
                transform.setGlobalScale(world.scale);
            }
        }
        private void dataChange(Yggdrasil.AsgardPose oldValue, Yggdrasil.AsgardPose newValue)
        {
          
           // _pose = pose;
            refresh();
            //transform.setGlobalScale(world.scale);
        }
    }
}
